package com.beamfield.controller.manage.steelplant;

import com.beamfield.common.ApiResult;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.*;
import com.beamfield.service.serviceimpl.manage.steelplant.SteelplantMillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 */
@Controller
@RequestMapping(value = "/cms/rebar/source-mill")
public class MillController extends BaseController {


    @Autowired
    private SteelplantMillService steelplantMillService;


    @RequestMapping(value = "/factoryBuildingPlan")
    public ModelAndView factoryBuildingPlan() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/equipmentFurnishmentPlan")
    public ModelAndView equipmentFurnishmentPlan() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/equipmentLayout")
    public ModelAndView equipmentLayout() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/peopleManagement")
    public ModelAndView peopleManagement() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/ labourPeopleManagement")
    public ModelAndView labourPeopleManagement() {
        return new ModelAndView();
    }
    //布置图
    @RequestMapping(value = "/edit_equipmentLayout")
    public ModelAndView edit_euipmentLayout() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/edit_factoryBuildingPlan")
    public ModelAndView edit_factoryBuildingPlan() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/detail_equipmentLayout")
    public ModelAndView detail_euipmentLayout() {
        return new ModelAndView();
    }


    @RequestMapping(value = "/edit_equipmentPlan")
    public ModelAndView edit_equipmentPlan() {
        return new ModelAndView();
    }


    @RequestMapping(value = "/addSteelplantDevcieLm")
    @ResponseBody
    public ApiResult addSteelplantDevcieLm(SteelplantDevcieLm steelplantDevcieLm, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevcieLm.setCreatorid(userId);
        steelplantDevcieLm.setBeam_id(beamId);
        steelplantDevcieLm.setCreatetime(new Date());

        int result = 0;
        try {
            result = steelplantMillService.addSteelplantDevcieLm(steelplantDevcieLm);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }

    }

    @RequestMapping(value = "/delSteelplantDevcieLm")
    @ResponseBody
    public ApiResult delSteelplantDevcieLm(SteelplantDevcieLm steelplantDevcieLm, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevcieLm.setCreatorid(userId);
        steelplantDevcieLm.setBeam_id(beamId);
        steelplantDevcieLm.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.delSteelplantDevcieLm(steelplantDevcieLm);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/updelSteelplantDevcieLm")
    @ResponseBody
    public ApiResult updelSteelplantDevcieLm(SteelplantDevcieLm steelplantDevcieLm, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevcieLm.setCreatorid(userId);
        steelplantDevcieLm.setBeam_id(beamId);
        steelplantDevcieLm.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.updelSteelplantDevcieLm(steelplantDevcieLm);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/querySteelplantDevcieLmAll")
    @ResponseBody
    public PageResult querySteelplantDevcieLmAll(SteelplantDevcieLmDTO steelplantDevcieLmDTO, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevcieLmDTO.setCreatorid(userId);
        steelplantDevcieLmDTO.setBeam_id(beamId);
        steelplantDevcieLmDTO.setCreatetime(new Date());

        int count = steelplantMillService.countSteelplantDevcieLmAll(steelplantDevcieLmDTO);
        List<Map> steelplantDevcieLms = steelplantMillService.querySteelplantDevcieLmAll(steelplantDevcieLmDTO);
        return new PageResult(count, steelplantDevcieLmDTO.getOffset(), steelplantDevcieLms);

    }

    @RequestMapping(value = "/querySteelplantDevcieLmOne")
    @ResponseBody
    public SteelplantDevcieLm querySteelplantDevcieLmOne(SteelplantDevcieLm steelplantDevcieLm, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        steelplantDevcieLm.setBeam_id(beamId);
        return steelplantMillService.querySteelplantDevcieLmOne(steelplantDevcieLm);
    }


    @RequestMapping(value = "/addSteelplantBuilding")
    @ResponseBody
    public ApiResult addSteelplantBuilding(SteelplantBuilding steelplantBuilding, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantBuilding.setCreatorid(userId);
        steelplantBuilding.setBeam_id(beamId);
        steelplantBuilding.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.addSteelplantBuilding(steelplantBuilding);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }

    }

    @RequestMapping(value = "/delSteelplantBuilding")
    @ResponseBody
    public ApiResult delSteelplantBuilding(SteelplantBuilding steelplantBuilding, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantBuilding.setCreatorid(userId);
        steelplantBuilding.setBeam_id(beamId);
        steelplantBuilding.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.delSteelplantBuilding(steelplantBuilding);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/updelSteelplantBuilding")
    @ResponseBody
    public ApiResult updelSteelplantBuilding(SteelplantBuilding steelplantBuilding, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantBuilding.setCreatorid(userId);
        steelplantBuilding.setBeam_id(beamId);
        steelplantBuilding.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.updelSteelplantBuilding(steelplantBuilding);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/querySteelplantBuildingAll")
    @ResponseBody
    public PageResult querySteelplantBuildingAll(SteelplantBuildingDTO steelplantBuildingDTO, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantBuildingDTO.setCreatorid(userId);
        steelplantBuildingDTO.setBeam_id(beamId);
        steelplantBuildingDTO.setCreatetime(new Date());

        int count = steelplantMillService.countSteelplantBuildingAll(steelplantBuildingDTO);
        List<Map> steelplantBuildings = steelplantMillService.querySteelplantBuildingAll(steelplantBuildingDTO);
        return new PageResult(count, steelplantBuildingDTO.getOffset(), steelplantBuildings);

    }

    @RequestMapping(value = "/querySteelplantBuildingOne")
    @ResponseBody
    public SteelplantBuilding querySteelplantBuildingOne(SteelplantBuilding steelplantBuilding, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        steelplantBuilding.setBeam_id(beamId);
        return steelplantMillService.querySteelplantBuildingOne(steelplantBuilding);
    }


    @RequestMapping(value = "/addSteelplantDevciePlan")
    @ResponseBody
    public ApiResult addSteelplantDevciePlan(SteelplantDevicePlanDTO steelplantDevciePlan, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevciePlan.setCreatorid(userId);
        steelplantDevciePlan.setBeam_id(beamId);
        steelplantDevciePlan.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.addSteelplantDevciePlan(steelplantDevciePlan);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }

    }

    @RequestMapping(value = "/delSteelplantDevciePlan")
    @ResponseBody
    public ApiResult delSteelplantDevciePlan(SteelplantDevicePlanDTO steelplantDevciePlan, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevciePlan.setCreatorid(userId);
        steelplantDevciePlan.setBeam_id(beamId);
        steelplantDevciePlan.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.delSteelplantDevciePlan(steelplantDevciePlan);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/updelSteelplantDevciePlan")
    @ResponseBody
    public ApiResult updelSteelplantDevciePlan(SteelplantDevicePlanDTO steelplantDevciePlan, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevciePlan.setCreatorid(userId);
        steelplantDevciePlan.setBeam_id(beamId);
        steelplantDevciePlan.setCreatetime(new Date());
        int result = 0;
        try {
            result = steelplantMillService.updelSteelplantDevciePlan(steelplantDevciePlan);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/querySteelplantDevciePlanAll")
    @ResponseBody
    public PageResult querySteelplantDevciePlanAll(SteelplantDevicePlanDTO steelplantDevciePlanDTO, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        steelplantDevciePlanDTO.setCreatorid(userId);
        steelplantDevciePlanDTO.setBeam_id(beamId);

        int count = steelplantMillService.countSteelplantDevciePlanAll(steelplantDevciePlanDTO);
        List<Map> steelplantDevciePlans = steelplantMillService.querySteelplantDevciePlanAll(steelplantDevciePlanDTO);
        return new PageResult(count, steelplantDevciePlanDTO.getOffset(), steelplantDevciePlans);

    }

    @RequestMapping(value = "/querySteelplantDevciePlanOne")
    @ResponseBody
    public SteelplantDevicePlan querySteelplantDevciePlanOne(SteelplantDevicePlanDTO steelplantDevciePlan, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        steelplantDevciePlan.setBeam_id(beamId);
        return steelplantMillService.querySteelplantDevciePlanOne(steelplantDevciePlan);
    }


}
